import {
  Controller,
  Get,
  Post,
  Body,
  HttpCode,
  HttpStatus,
  Request,
  Headers,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginAuthDto } from './dto/login-auth.dto';
import { SkipAuth } from '@/guard/skipAuth.guard';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  // 这里传入空数组，表示不使用任何守卫，覆盖jwt守卫
  @HttpCode(HttpStatus.OK)
  @Post('login')
  @SkipAuth()
  login(@Body() loginAuthDto: LoginAuthDto) {
    return this.authService.login(loginAuthDto);
  }

  @Post('logout')
  @SkipAuth()
  logout(@Headers('authorization') authorization: string) {
    this.authService.logout(authorization);
    return {
      code: 200,
      message: '退出登录成功',
      data: null,
    };
  }

  @Get('jwtInfo')
  getProfile(@Request() req) {
    return req.user;
  }
}
